#include<iostream>
using namespace std;
#include<vector>
#include<queue>
class Solution {
public:
    int arr[260000] = { 0 };
    int cal(int now) {
        int ans = 0;
        while (now != 1) {
            ++ans;
            if (now % 2 == 0)
                now /= 2;
            else
                now = now * 3 + 1;
        }
        return ans;
    }
    class cmp {
    public:
        bool operator()(pair<int, int>& a1, pair<int, int>& a2) {
            return a1.second < a2.second || (a1.second == a2.second && a1.first < a2.first);
        }
    };
    int getKth(int lo, int hi, int k) {
        for (int i = lo; i <= hi; ++i)
            arr[i] = cal(i);
        priority_queue<pair<int, int>, vector<pair<int, int>>, cmp> que;
        for (int i = lo; i <= hi; ++i)
            que.push({ i,arr[i] });
        while (que.size() > k)
            que.pop();
        return que.top().first;
    }
};